<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class ImageModel extends Model
{
    // 列出首页滑动图片
    public static function swiper_img_list()
    {
        $list = DB::table('swiper_img')->select('id', 'alt', 'filename', 'go', 'creat_id', 'created_at', 'updated_at')->orderBy('created_at', 'desc')->get();
        return $list;
    }

    // update swiper
    public static function swiper_update($id, $update_array)
    {
        if (DB::table('swiper_img')->where('id', $id)->exists()) {
            $update_array['updated_at'] = date('Y-m-d h:i:s');
            DB::table('swiper_img')->where('id', $id)->update($update_array);
            return true;
        } else {
            return false;
        }
    }

    // add swiper
    public static function swiper_add($id, $update_array)
    {
        $array['id'] = $id;
        $array['creat_id'] = Auth::id();
        $array['created_at'] = date('Y-m-d h:i:s');
        $array['updated_at'] = date('Y-m-d h:i:s');
        if (DB::table('pro_alone')->insert($array))
            return true;
        else
            return false;
    }
}
